define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'sheji/index' + location.search,
                    add_url: 'sheji/add',
                    edit_url: 'sheji/edit',
                    del_url: 'sheji/del',
                    multi_url: 'sheji/multi',
                    import_url: 'sheji/import',
                    table: 'sheji',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                clickToSelect: false, //是否启用点击选中
                dblClickToEdit: false, //是否启用双击编辑  
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'fname', title: __('Fname'), operate: 'LIKE'},
                        {field: 'shejit.tname', title: '文件分类', operate: 'LIKE'},
                        {field: 'fpath_files', title: __('Fpath_files'), operate: false, formatter: Table.api.formatter.files},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
                         {field: '测试', title: __('测试'), table: table, events: Table.api.events.operate, formatter: function(){
                             return "<button class=\"btn btn-success\" id=\"ceshi\">测试</button>"
                         }}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            
            $(document).on("click","#ceshi",function(){
                alert(1234);
            })
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
